﻿<?php
include ('msg_queue.php');
    $msgtype=0;
    $msqid=0;
    $buf;
    $key;


    if (($key = ftok("kirk.php", 'B')) == -1) {  /* same key as kirk.c */
        echo "błąd ftok\n";
        exit(1);
    }


//    if (($msqid = msg_get_queue($key, 0666)) == -1) { /* connect to the queue */
//        echo"błąd msgget\n";
//        exit(1);
//    }
 $msqid=create_message_queue($key); 
    
    printf("spock: ready to receive messages, captain.\n");


    for(;;) { /* Spock never quits! */
            //msg_receive ( resource $queue , int $desiredmsgtype , int &$msgtype , int $maxsize , mixed &$message [, bool $unserialize = true [, int $flags = 0 [, int &$errorcode ]]] )
                $message = NULL;
                $err = NULL;
                
          //msg_receive($msqid, 1/*desired*/, $real_type, 16384, $message, 1/*ser*/,0,$err);
        if (receive_message($key, $message, 16384,true)== -1 ) {
            echo "błąd msgrcv: $err\n";
            exit(1);
        }
        
        echo"kirk: \"".$message."\"\n";
    }


?>